<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button id="btn">新歌速递</button>
  <ul id="ul">

  </ul>

  <script>
    const btn = document.getElementById('btn');
    btn.addEventListener('click', () => {
      // 朝网易云的服务器上的后端代码发一个http请求
      let xhr = new XMLHttpRequest();
      xhr.open('GET', 'http://192.168.31.45:3000/top/song?type=7', true);
      xhr.onreadystatechange = () => {
        if (xhr.readyState === 4 && xhr.status === 200) {
          
          let result = JSON.parse(xhr.responseText)
          

          result.data.forEach(song => {
            let li = document.createElement('li');
            li.innerHTML = song.name
            document.getElementById('ul').appendChild(li)
          });





        }
      }
      xhr.send();

    })
  </script>

  <!-- <script>

    let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

    arr.forEach((a, b, c) => {
      console.log(a, b);
    })



  </script> -->
</body>
</html>